/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx.interceptor;

import com.mysql.cj.log.Log;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.reflection.SystemMetaObject;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Properties;

/**
 * <p></p>
 * <p>Powered by webrx On 2023-04-20 17:30:19</p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@Intercepts({
        @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
})
public class ExamplePlugin implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("Object intercept(Invocation invocation)...........................拦截器执行");
        Method method = invocation.getMethod();
        System.out.println(method.getName());
        Object target = invocation.getTarget();
        System.out.println(target.getClass().getSimpleName());
        Object[] args = invocation.getArgs();
        System.out.println(Arrays.toString(args));

        var mh = SystemMetaObject.forObject(target);
        String[] getterNames = mh.getGetterNames();
        System.out.println(Arrays.toString(getterNames));
        String[] setterNames = mh.getSetterNames();
        System.out.println(Arrays.toString(setterNames));
        //var ms = (MappedStatement) mh.getValue("delegate.mappedStatement");
        //String msid = ms.getId();
        //System.out.println(msid);



        Object obj = invocation.proceed();
        return obj;
    }

}
